﻿using System;
using System.IO;

namespace mst_regex
{
    internal struct StockPriceRecord
    {
        public decimal Change;
        public decimal Close, High, Low;
        public decimal Open;
        public string Ticker;
        public decimal Trades;
        public decimal Value;
        public decimal Volume;
    }

    internal class Program
    {
        private const int GRP_TICKER = 1;
        private const int COL_OPEN = 0;
        private const int COL_HIGH = COL_OPEN + 1;
        private const int COL_LOW = COL_HIGH + 1;
        private const int COL_CLOSE = COL_LOW + 1;
        private const int COL_CHG = COL_CLOSE + 1;
        private const int COL_TRADES = COL_CHG + 1;
        private const int COL_VOLUME = COL_TRADES + 1;
        private const int COL_VALUES = COL_VOLUME + 1;

        private static string getunpass()
        {
            var strArray = new[]
                               {
                                   "jpg", "itag", "fbh", "sAl", "drh", "dnu", "2n8", "mO19", "wdo", "aw5", "27j", "sv7",
                                   "xx3", "s39", "7yy", "qsd",
                                   "at", "dim", "ac", "as", "34", "21", "se", "5t", "38", "fr6", "d8", "2g", "sdf", "34"
                                   , "dgu8", "a2r",
                                   "avh", "asw", "20", "aw", "vb"
                               };
            string str = "";
            return ((((str + strArray[3]) + strArray[7] + strArray[12]) + strArray[14] + strArray[0x11]) +
                    strArray[0x13] + strArray[0x18]);
        }

        private static void writeFile(byte[] data, int i)
        {
            using (var ms = new MemoryStream(data))
            {
                using (var fs = new FileStream("proto" + i, FileMode.Create, FileAccess.Write))
                {
                    byte[] buffer = new byte[8192];
                    int bytesRead;
                    while ((bytesRead = ms.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fs.Write(buffer, 0, bytesRead);
                    }
                }
            }
        }

        private static void Main(string[] args)
        {
            var dat = File.ReadAllText("mst.txt");
            var parser = new DseDailyMarketStatisticsParser();
            var stats = parser.ParseMakertStatisticsData(dat, DateTime.Today);
            writeFile(stats.ToProtobuf(), 1);
            var xxx = DailyMarketStatistics.FromProtobuf(File.ReadAllBytes("proto1"));
            writeFile(xxx.ToProtobuf(), 2);
            //Console.WriteLine(DayOfWeek.Friday);
            //Console.WriteLine(getunpass());
            //Console.WriteLine(stats.SpotTransactions.StockPositions[0].ToXml());
            //Console.WriteLine(stats.SpotTransactions.ToXml());

            Console.WriteLine(stats.SpotTransactions.StockPositions[0].ToCsv());
            return;


            /*
            Console.WriteLine(DayOfWeek.Friday);
            Console.WriteLine(getunpass());
            string[] mstLines = File.ReadAllLines("mst.txt");
            string[] graphLines = File.ReadAllLines("companygraph.txt");

            var list = new StockPositions();
            var mst = new MstParserDse(list);
            mst.ParseDocument(String.Join("\r\n", mstLines), String.Join("\r\n", graphLines));

            var sched = new EodScheduler();
            DayOfWeek[] dows = sched.GetWeekends();
            //sched.AddWeekend(DayOfWeek.Sunday);
            sched.TimeStart = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 19, 30, 0);

            bool b = sched.CheckTime(DateTime.Now);

            Console.WriteLine("{0} items", list.Count);

            var settings = new AppSettings("zeitgeist.conf");
            settings.LoadSettings();

            settings.AbDatabase = "db";
            settings.AbExecutable = "loc";
            settings.StartHours = 15;
            settings.StartMinutes = 45;
            settings.CsvFolder = "csv";
            settings.ProxyAddress = "";
            settings.UseProxy = false;
            settings.ProxyPort = 0;
            settings.ProxyPass = "";
            settings.ProxyUser = "";
            settings.Weekends = sched.GetWeekends();

            settings.SaveSettings();
             */
        }
    }
}